#!/bin/bash


Dir=$(pwd)
md5=$(md5sum dingtalk-robot.py |cut -d' ' -f 1)
[ -f .md5.log ] || { touch .md5.log; }

dockerRun() {
docker rm -f robot-dingtalk &>/dev/null
docker run -dit --name robot-dingtalk \
 --restart=always -h robot-dingtalk --net=host\
 -v $Dir:/opt --env-file .env_dingtalk \
registry.aliyuncs.com/elvin/python:dingtalk-robot \
python3 /opt/dingtalk-robot.py
docker ps -a |grep robot-dingtalk
}

if [ "$md5" != "$(cat .md5.log)" ]; then
  dockerRun
  echo $md5 > .md5.log
else
  docker ps |grep robot-dingtalk || dockerRun
fi

